package com.shine.commonlibrary.utils.commonwidget;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shine.commonlibrary.R;
import com.shine.commonlibrary.utils.base.BaseActivity;
import com.shine.commonlibrary.utils.base.BaseDialogFragment;

/**
 * Created by M_genius on 2017/6/27 16:33.
 * 描述：退出登录显示的提示对话框
 */

public class LogoutDialog extends BaseDialogFragment implements View.OnClickListener {

    TextView mTvCancel;
    TextView mTvOk;

    OnLoginOutListener mOnLoginOutListener;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_logout;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);

        mTvOk = (TextView) view.findViewById(R.id.tv_ok);
        mTvCancel = (TextView) view.findViewById(R.id.tv_cancel);

        mTvOk.setOnClickListener(this);
        mTvCancel.setOnClickListener(this);

        return view;
    }


    public void setOnConfirmListener(OnLoginOutListener onConfirmListener) {
        mOnLoginOutListener = onConfirmListener;
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.tv_cancel) {
            if (mOnLoginOutListener != null) {
                mOnLoginOutListener.onCancel();
            }
            dismiss();

        } else if (i == R.id.tv_ok) {
            if (mOnLoginOutListener != null) {
                mOnLoginOutListener.onConfirm();
            }
            dismiss();
        }
    }

    public static void Show(BaseActivity activity, OnLoginOutListener onConfirmListener) {
        LogoutDialog mDialog = new LogoutDialog();
        mDialog.setOnConfirmListener(onConfirmListener);
        mDialog.show(activity.getSupportFragmentManager(), LogoutDialog.class.getName());
    }

    public interface OnLoginOutListener {
        void onConfirm();

        void onCancel();
    }
}